package nc.ui.uif2.actions;

import java.awt.event.ActionEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import nc.ui.querytemplate.querytree.IIconDecorator;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.UIState;
import nc.ui.uif2.model.BillTableModel;

public class CancelTableEditAction extends NCAction
{
  private static final long serialVersionUID = -5936618898272340823L;
  private BillTableModel model = null;

  public static final Icon CANCEL_ICON = new ImageIcon(IIconDecorator.class.getResource("/images/toolbar/icon/cancel.gif"));

  public CancelTableEditAction()
  {
    ActionInitializer.initializeAction(this, 7);
    putValue("SmallIcon", CANCEL_ICON);
  }

  public void doAction(ActionEvent e) throws Exception
  {
    this.model.setUiState(UIState.INIT);
  }

  protected boolean isActionEnable()
  {
    return (this.model.getUiState() == UIState.EDIT) || (this.model.getUiState() == UIState.ADD);
  }

  public BillTableModel getModel()
  {
    return this.model;
  }

  public void setModel(BillTableModel model) {
    this.model = model;
    this.model.addAppEventListener(this);
  }
}